//
//  YFTabBarItem.swift
//  微博
//
//  Created by 余仿 on 16/4/15.
//  Copyright © 2016年 YF. All rights reserved.
//

import UIKit

class YFTabBarItem: UITabBarItem {


    override var badgeValue:String?{

        didSet{

//            需要获取_tabBarItem的成员变量_target
            let tb = self.valueForKey("_target")

//            赋值的同时,将target赋值

//            item自带属性
            for subView in (tb!.tabBar.subviews){

                if subView.isKindOfClass(NSClassFromString("UITabBarButton")!){

                    for sub in subView.subviews{

                        if sub.isKindOfClass(NSClassFromString("_UIBadgeView")!){

                            for s in sub.subviews{

                                if s.isKindOfClass(NSClassFromString("_UIBadgeBackground")!){

                                    s.setValue(UIImage(named: "main_badge"), forKey: "_image")
                                }
                            }
                            
                        }
                    }
                }
            }
        }
    }
}
